package com.qfedu.buy.server.controller;

import cn.hutool.crypto.SecureUtil;
import com.qfedu.buy.server.config.KeyConfig;
import com.qfedu.buy.server.util.ZxingUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Base64;

/**
 * @program: NeighborBuy
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-02-01 14:23
 */
@Controller
@RequestMapping("/pay/qrcode/")
public class QrCodeController {
    @GetMapping("/pay.png")
    public void createQrcode(String msg, HttpServletResponse response) throws IOException {
        //msg 密文
        //解密
        String content= SecureUtil.aes(Base64.getDecoder().decode(KeyConfig.PAY_KEY)).decryptStr(msg);
        //生成二维码
        BufferedImage image= ZxingUtil.createImage(content,KeyConfig.PAYQRCODE_SIZE);
        ImageIO.write(image,"png",response.getOutputStream());
    }
}